class Solution:
    def canPlaceFlowers(self, flowerbed, n: int) -> bool:
        width=len(flowerbed)
        for i in range(width):
            if n==0:
                return True
            if i==0 and flowerbed[i]==0:
                if i==width-1 or flowerbed[i+1]==0:
                    n-=1
                    flowerbed[i]=1
                continue
            if i==width-1 and flowerbed[i]==0 and flowerbed[i-1]==0:
                n-=1
                flowerbed[i]=1
                continue
            if flowerbed[i]==0 and flowerbed[i-1]==0 and flowerbed[i+1]==0:
                flowerbed[i]=1
                n-=1
                continue
        return n==0

s=Solution()
print(s.canPlaceFlowers([0,0,0],2))


'''
执行用时：
60 ms
, 在所有 Python3 提交中击败了
50.21%
的用户
内存消耗：
14.8 MB
, 在所有 Python3 提交中击败了
65.13%
的用户
'''